﻿    .equ    ConsCtrl 2
    .equ    ConsData 3
    .equ    DiskCtrl 4
    .equ    DiskData 5
    .equ    READY 1
    .equ    READ 2
    .equ    SET0 0x10
    .equ    SET1 0x20
    .equ    SET2 0x40
    .equ    FAddr 0

.section .text at 0:
    .global _main
_main:
    halt

.section int_handler at 0x6000:
    .global _getc at 0x6000
_getc:
#input interrupt,get a char from console input
#r8: char
    set     r16,@READY
    write   r16,1,@ConsCtrl
    read    r16,1,@ConsCtrl
    jmp     r16,ne,-2
    read    r8,1,@ConsData
    iret

    .global _putc at 0x6040
_putc:
#print interrupt,put a char to console output
#r0: char
    write   r0,1,@ConsData
    set     r16,@READY
    write   r16,1,@ConsCtrl
    read    r16,1,@ConsCtrl
    jmp     r16,ne,-2
    iret

    .global _gets at 0x6080
_gets:
#input interrupt,get a string from console input
#r0: buffer addr
#r1: max length
    set     r16,0
    iret

    .global _puts at 0x60c0
_puts:
#print interrupt,put a string to console output
#r0: string addr
#r1: length
    set     r16,0
    iret

    .global _disk_read at 0x6100
_disk_read:
#disk read interrupt
#r0: sector number
#r1: buffer address
#r2: number of sectors
    set     r16,@READY
    iret

    .global _disk_write at 0x6140
_disk_write:
#disk write interrupt
#r0: sector number
#r1: buffer address
#r2: number of sectors
    set     r16,@READY
    iret


.section .rodata at 0x2000:
    .string _comment1 0x2000 "Start stage 2,loading int table...\n"
    .string _comment2 0x2020 "Int table loaded.\nInterrupts enabled,initializing int tables...\n"
    .byte   _sizes 0x2100 35,64
    .8byte  int_table 0x4000 0,0x6000,0x6040,0x6080